package com.example.entity.message.impl;

import com.example.constant.MessageConstant;
import com.example.constant.MessageTypeConstant;
import com.example.constant.SendReasonConstant;
import com.example.entity.Attachment;
import com.example.entity.body.impl.ASDUBody;
import com.example.entity.header.Header;
import com.example.entity.message.Message;

import io.netty.buffer.ByteBuf;

public class RemoteElectricAffirmMessage extends Message {
	public RemoteElectricAffirmMessage() {
		// TODO Auto-generated constructor stub
		Header header = new Header();
		ASDUBody body = new ASDUBody();

		header = new Header();
		header.setContextLength(0x2b);
		header.setUControlField(0x7000000);

		body.setType(MessageTypeConstant.REMOTE_ELECTRIC_MESSAGE_SC);
		body.setVaristructureDet(0x1);
		body.setSendReason(SendReasonConstant.START);
		body.setAddr(0x1);

		setHeader(header);
		setBody(body);
	}

	@Override
	public void setAttachment(ByteBuf buf) throws Exception {
		// TODO Auto-generated method stub
		Attachment attachment = new Attachment(buf, MessageTypeConstant.REMOTE_ELECTRIC_MESSAGE_SC, (byte) 0x3,
				MessageConstant.HASVAlUE, MessageConstant.NOQDS);
		Attachment[] attachments = { attachment };
		if (buf.readableBytes() != 0) {
			throw new Exception("远程充电确认报文的附属项设置错误");
		}
		((ASDUBody) getBody()).setAttachments(attachments);
	}
}
